package cn.edu.ctbu.lddweb.controller;

import cn.edu.ctbu.lddweb.pojo.Logon;
import cn.edu.ctbu.lddweb.pojo.Student;
import cn.edu.ctbu.lddweb.service.LogonService;
import cn.edu.ctbu.lddweb.service.StudentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.List;

/**
 * 个人中心
 */
@Controller
public class PersonController {

    @Autowired
    private LogonService logonService;

    @Autowired
    private StudentService studentService;

    //个人中心
    @RequestMapping("/person/edit")
    public String edit(Model model, String username, ModelMap map, Logon logon, Student student) {
        logon.setUsername(username);
        List<Logon> list = logonService.selectList(logon);
        if (list.size() != 0) {
            map.put("id",list.get(0).getId());
            map.put("username",list.get(0).getUsername());
            map.put("pwd",list.get(0).getPwd());
            map.put("sex",list.get(0).getSex());
            map.put("className",list.get(0).getClassName());
            map.put("gradeName",list.get(0).getGradeName());
            map.put("courseName",list.get(0).getCourseName());
//            model.addAttribute("logon", list);
        }
        return "/person/edit";
    }

    //修改操作（超级管理员）
    @RequestMapping("/updatePerson")
    public String updateGrade(Model model, String username, ModelMap map, Logon logon) {
        logonService.updateLogon(logon);
        List<Logon> list = logonService.selectList(logon);
//        if (list.size() != 0) {
            map.put("id",list.get(0).getId());
            map.put("username",list.get(0).getUsername());
            map.put("pwd",list.get(0).getPwd());
            map.put("sex",list.get(0).getSex());
            map.put("className",list.get(0).getClassName());
            map.put("gradeName",list.get(0).getGradeName());
            map.put("courseName",list.get(0).getCourseName());
//            model.addAttribute("logon", list);
//        }
        return "/person/edit";
    }

}
